home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE02 / TPACK / TPACK.ZIP / USERINFO.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-06-02  |  6.6 KB  |  212 lines

  1. {------------------------------------------------------------------------------}
  2. {UNREGISTERED VERSION (6/1/95) PLEASE REDISTRIBUTE IN tPACK.ZIP!
  3.  This revision does not contain everything, nor are the exciting
  4.  DataSetReporter and ExtendedMenu[Item] components included.
  5.  Use SWREG#5906 to receive these, icons and a help file for $130.
  6.  You must register when using this code in a business application!
  7.  You'll receive a license to use this code in up to 50 copies of
  8.  any app you write. In turn you will get responsive e-mail
  9.  tech support and enhancements till I run out of registrations
  10.  or suggestions. Meanwhile.. enjoy the code. Bye! I'll make more.
  11.  {(C)'1995 Michael/Ax-Systems, 71560,1754@Compuserve.com}
  12. {------------------------------------------------------------------------------}
  13.  
  14. unit UserInfo;
  15.  
  16. interface
  17.  
  18. uses
  19.   Classes, SysUtils, Wincrt, IniFiles, WinTypes, WinProcs, dbtables, Controls
  20. , PasUtils
  21. , Xtension
  22. , Debug;
  23.  
  24. Type
  25.  
  26.   TComponentExtended = class(TComponent)
  27.     cx: TComponentExtensions;
  28.   public
  29.     Constructor Create(aOwner:TComponent); Override;
  30.     Destructor Destroy; Override;
  31.     end;
  32.  
  33.   TUserInfoOptionTypes = (uifUpdateOnLoad,uifUpdateInDesign,uifUpdateOnGet);
  34.   TUserInfoOptions     =  set of TUserInfoOptionTypes;
  35.   TUserInfoStateTypes  = (uifUpdating,uifUpdated);
  36.   TUserInfoState       =  set of TUserInfoStateTypes;
  37.  
  38.   TUserInfo = class(TComponentExtended)
  39.   private
  40.     fOptions: TUserInfoOptions;
  41.     fState: TUserInfoState;
  42.   protected
  43.     function GetState:TUserInfoState;
  44.     procedure SetState(Value:TUserInfoState);
  45.     function GetUpdated: Boolean;
  46.     procedure SetUpdated(Value:Boolean);
  47.     function  CanUpdate:Boolean;
  48.   public
  49.     Constructor Create(aOwner:TComponent); Override;
  50.     procedure Loaded; Override;
  51.     procedure Update;
  52.     function UpdateOK:Boolean; Virtual;
  53.   published
  54.     property Options: TUserInfoOptions read fOptions write fOptions; {what we can do}
  55.     property State: TUserInfoState read fState write SetState stored False; {what we did}
  56.     property Updated: Boolean read GetUpdated write SetUpdated stored false; {if we did}
  57.     end;
  58.  
  59.   TDialogShell = class(TComponentExtended)
  60.   protected
  61.     procedure SetTest(Value:Boolean); virtual;
  62.     function GetTest:Boolean; virtual;
  63.   public
  64.     constructor Create(aOwner:Tcomponent); Override;
  65.     procedure Execute; virtual;
  66.   published
  67.     property Test: Boolean read GetTest write SetTest stored False;
  68.     end;
  69.  
  70. implementation
  71.  
  72. uses Dialogs;
  73.  
  74. {-----------------------------------------------------------------------------------------}
  75. {                                                                                         }
  76. {-----------------------------------------------------------------------------------------}
  77. {-----------------------------------------------------------------------------------------}
  78. { TComponentExtended OBJECT CREATION                                                      }
  79. {-----------------------------------------------------------------------------------------}
  80.  
  81. Constructor TComponentExtended.Create(aOwner:TComponent);
  82. begin
  83.   inherited Create(aOwner);
  84.   cx:=TComponentExtensions.Create(Self);
  85.   if (decCreate in DebugFlags) then
  86.     if Owner=nil then
  87.       DebugLog(Owner,'Create '+ClassName+' (nil)')
  88.     else
  89.       DebugLog(Owner,'Create '+ClassName+' ('+Owner.Name+':'+Owner.ClassName+')');
  90. end;
  91.  
  92. Destructor TComponentExtended.Destroy;
  93. begin
  94.   if (decDestroy in DebugFlags) then
  95.     DebugLog(Owner,'Destroy '+ClassName);
  96.   cx.Free;
  97.   inherited Destroy;
  98. end;
  99.  
  100. {-----------------------------------------------------------------------------------------}
  101. { TDialogShell  BASE OBJECT  OBJECT CREATION                                              }
  102. {-----------------------------------------------------------------------------------------}
  103.  
  104. Constructor TDialogShell.Create(aOwner:TComponent);
  105. begin
  106.   inherited Create(aOwner);
  107. end;
  108.  
  109. procedure TDialogShell.Execute;
  110. begin
  111. end;
  112.  
  113. procedure TDialogShell.SetTest(Value:Boolean);
  114. begin
  115.   Execute;
  116. end;
  117.  
  118. function TDialogShell.GetTest:Boolean;
  119. begin
  120.   Result:=True;
  121. end;
  122.  
  123.  
  124. {-----------------------------------------------------------------------------------------}
  125. { TUserInfo  BASE OBJECT  OBJECT CREATION                                                 }
  126. {-----------------------------------------------------------------------------------------}
  127.  
  128. Constructor TUserInfo.Create(aOwner:TComponent);
  129. begin
  130.   inherited Create(aOwner);
  131.   Options:=[uifUpdateOnLoad,uifUpdateInDesign,uifUpdateOnGet];
  132. end;
  133.  
  134. procedure TUserInfo.Loaded;
  135. begin
  136.   if (decLoaded in DebugFlags) then
  137.     DebugLog(Owner,'Loaded '+ClassName);
  138.   inherited Loaded;
  139.   if not (csDesigning in ComponentState) then
  140.     if uifUpdateOnLoad in Options then
  141.       Update {actually 'update on load'}
  142.     else
  143.   else
  144.     if uifUpdateInDesign in Options then
  145.       Update; {might be ok to update in design mode as well}
  146. end;
  147.  
  148. procedure TUserInfo.SetState(Value:TUserInfoState);
  149. begin
  150. {basically read-only, showing if prop editor because this proc is ref'd}
  151. {made sensitive to -uifUpdated to allow cx.NilIfSet to unupdate a Userinfo Component}
  152.   if Value=fState-[uifUpdated] then
  153.     fState:=Value;
  154. end;
  155.  
  156. function TUserInfo.GetState:TUserInfoState;
  157. {purpose is to call the update proc when we try to turn the property on.}
  158. begin
  159.   if uifUpdateOnGet in Options then
  160.     Update;
  161.   Result:=fState;
  162. end;
  163.  
  164. function TUserInfo.GetUpdated: Boolean;
  165. begin
  166.   if uifUpdateOnGet in Options then
  167.     Update;
  168.   Result:=uifUpdated in State; {might trigger autoupdate on read. that why we have the proc!}
  169. end;
  170.  
  171. procedure TUserInfo.SetUpdated(Value:Boolean);
  172. begin
  173.   if not Value then
  174.     State:= State - [uifUpdated]
  175.   else
  176.     if not (uifUpdated in State) and Value then
  177.       Update;
  178. end;
  179.  
  180. procedure TUserInfo.Update;
  181. begin
  182.   if ([uifUpdating,uifUpdated]*fState)<>[] then {sets intersect,e.g. state is either updating or updated}
  183.     exit;
  184.   fState:=fState+[uifUpdating]; {MUST access field, changing this property does not change the field!}
  185.   if CanUpdate then
  186.     fState:=fState+[uifUpdated];
  187.   fState:=fState-[uifUpdating];
  188. end;
  189.  
  190. function TUserInfo.CanUpdate:Boolean;
  191. {purpose is to call the update proc when we try to turn the property on.}
  192. begin
  193.  
  194.   if (decUpdate in DebugFlags) then
  195.     with cx do begin
  196.       DebugLog(Owner,'+Update '+Self.ClassName);
  197.       Result:=UpdateOK;
  198.       DebugLog(Owner,'-Update '+Self.ClassName+':= '+BoolString[Result]);
  199.       end
  200.   else
  201.     Result:=UpdateOK {finally we see if it's ok to update now}
  202. end;
  203.  
  204. function TUserInfo.UpdateOK:Boolean; {The 'Ancestor'}
  205. begin
  206.   Result:= True;
  207. end;
  208.  
  209. end.
  210.  
  211.  
  212.